package com.lagou.login.controller;

import com.lagou.login.entiy.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Objects;

/**
 * @Description
 * @Author ch'ien
 * @Date 2021/4/26 15:14
 **/
@RestController
@RequestMapping("user")
public class LoginControlller {

    @Autowired
    private UserMapper userMapper;
    @GetMapping("/login")
    public String login(String name, String password, HttpSession session){
        User user = userMapper.getOneByName(name);
        if (user == null){
            return "login fail";
        }
        if (Objects.equals(user.getPassword(), password)){
            session.setAttribute("user", user);
            return "successful";
        }   else {
            return "Password verification fail";
        }

    }
}
